package com.cjzuji.rental.Bean;

import lombok.Data;

@Data
public class ApiResponse<T> {
    private String code;
    private String msg;
    private T data;

    // 构造函数
    public ApiResponse(String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // 静态方法，用于快速创建成功响应
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>("200", "Success", data);
    }


    // 静态方法，用于快速创建失败响应
    public static <T> ApiResponse<T> error(String code, String msg) {
        return new ApiResponse<>(code, msg, null);
    }

    // 失败响应
    public static <T> ApiResponse<T> fail(String code, String msg) {
        return new ApiResponse<>(code, msg, null);
    }
}
